class Solution {
public:
    bool evaluateTree(TreeNode* root) {
        return  dfs(root);
    }

    bool dfs(TreeNode* root)
    {
        if(root->left==nullptr&&root->right==nullptr)return root->val;
        if(root->val==2)
        {
            return dfs(root->left)||dfs(root->right);
        }
        else
        {
            return dfs(root->left)&&dfs(root->right);
        }

    }
};
